package com.tuanzi.loan.web.bean.family;

import com.google.common.collect.Lists;
import com.tuanzi.loan.business.service.family.ProductMatchRuleService;
import com.tuanzi.loan.core.aspect.Debug;
import com.tuanzi.loan.vo.request.family.ProductMatchRuleSearchRequest;
import com.tuanzi.loan.vo.response.family.ProductMatchRuleSearchResponse;
import com.tuanzi.loan.web.configuration.JSFListingSessionBean;
import com.tuanzi.loan.web.lazy.family.ProductMatchRuleLazyDataModel;
import lombok.Data;
import lombok.EqualsAndHashCode;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.faces.bean.ViewScoped;
import java.util.List;

import static com.tuanzi.loan.business.constants.DictionaryCode.ADVERT_POSITION;
import static com.tuanzi.loan.business.constants.DictionaryCode.RECOMMEND_POSITION;

/**
 * @author Ray 2017/09/21
 */
@Data
@Debug
@Component
@ViewScoped
@EqualsAndHashCode(callSuper = true)
public class MatchRuleListBean extends JSFListingSessionBean<ProductMatchRuleSearchRequest, ProductMatchRuleSearchResponse> {

    private static final long serialVersionUID = -2152778554108785342L;

    @Autowired
    private ProductMatchRuleService productMatchRuleService;

    public void onReset() {
        initLazyDataModel();
    }

    public String onAdd() {
        return redirect("/views/family/tags/rule/info.xhtml");
    }

    public String onEdit(String id) {
        return redirect("/views/family/tags/rule/info.xhtml?id=" + id);
    }


    @Override
    protected String page() {
        return "/views/family/tags/rule/list.xhtml";
    }

    @Override
    protected void initLazyDataModel() {
        $ = new ProductMatchRuleSearchRequest();
        lazyDataModel = new ProductMatchRuleLazyDataModel($, session, productMatchRuleService);
    }

    @Override
    protected List<String> getDictionaryCodes() {
        return Lists.newArrayList(RECOMMEND_POSITION, ADVERT_POSITION);
    }

}
